package core;

import gui.menus.Preferences;
import t2s.SIVOXDevint;

/**
 * Voice class<BR />
 * A singleton class that allows any class
 * from the project to access the play
 * method in order to play a message.
 * @author Y. Bondue
 * @version 1.0.0
 */
public class Voice {
	
	private static volatile Voice selfInstance;
	private SIVOXDevint voix;
	
	private Voice() {
		voix = Preferences.getData().getVoice();
		voix.setVoix(4);
		voix.setProsodie(3);
		voix.stop();
	}
	
	public static Voice getInstance() {
		if (selfInstance == null)
			selfInstance = new Voice();
		return selfInstance;
	}
	
	public void play(String message) {
		voix.stop();
		voix.playText(message);
	}

	public void playWav(String pathToWav) {
		voix.stop();
		voix.playWav(pathToWav);
	}
	
	public void stop() {
		voix.stop();
	}

	public void playWithoutInterruption(String message) {
		voix.stop();
		voix.playText(message);
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	
	public void playShortMessageWithoutInterruption(String message) {
		voix.stop();
		voix.playText(message);
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
}
